package com.hzz.web.boss.analysis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.hzz.api.examine.IExamineResultService;
import com.hzz.dto.analysis.ExamineResultLevelStatDto;
import com.hzz.dto.analysis.ExamineResultRankStatDto;
import com.hzz.framework.Response;
import com.hzz.framework.annotation.auth.RequiresPermissions;
import com.hzz.framework.util.DateUtil;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;

@Api("考核结果统计分析")
@RestController
@Slf4j
@RequestMapping("/boss/analysis/examineResultStat")
public class ExamineResultStatController {
	@Autowired
	private IExamineResultService examineResultService;

	/**
	 * 考核排名统计
	 * 
	 * @param dto
	 * @return
	 */
	@RequiresPermissions("analysis:examine:ranking")
	@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }, value = "/statResultRankByParentAreaId")
	public Response statResultRankByParentAreaId(@ModelAttribute ExamineResultRankStatDto dto) {
		log.info("statResultRankByParentAreaId.........{}", dto);
		Response result = new Response();
		try {
			result.data = examineResultService.statResultRankByParentAreaId(dto);
		} catch (Exception e) {
			log.error("statResultRankByParentAreaId error", e);
			result = Response.error(e.getMessage());
		}
		return result;
	}

	/**
	 * 考核等级统计
	 * 
	 * @param dto
	 * @return
	 */
	@RequiresPermissions("analysis:examine:level")
	@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }, value = "/statResultLevelByParentAreaId")
	public Response statResultLevelByParentAreaId(@ModelAttribute ExamineResultLevelStatDto dto) {
		log.info("statResultLevelByParentAreaId.........");
		Response result = new Response();
		try {
			if (dto.getYear() == null) {
				dto.setYear(DateUtil.getLastYear());
			}
			result.data = examineResultService.statResultLevelByParentAreaId(dto);
		} catch (Exception e) {
			result = Response.error(e.getMessage());
		}
		return result;
	}
}
